#include <chrono>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/timer.hpp>
#include <std_msgs/msg/int64.hpp>

using namespace std::chrono_literals;

class PrintIntNode : public rclcpp::Node {
public:
  PrintIntNode(std::string name) : Node(name) {
    pub_ = this->create_publisher<std_msgs::msg::Int64>("print_integer_pub", 10);
    timer_ = this->create_wall_timer(
        1s, std::bind(&PrintIntNode::timerCallback, this));
  }

  void timerCallback() {
    // Create a message object
    auto msg = std_msgs::msg::Int64();
    static int i = 0;
    msg.data = i++;
    // Publish the message
    pub_->publish(msg);
  }

private:
  rclcpp::TimerBase::SharedPtr timer_{nullptr};
  rclcpp::Publisher<std_msgs::msg::Int64>::SharedPtr pub_{nullptr};
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<PrintIntNode>("print_integer_node");
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}